package listener;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.apache.log4j.Logger;
 
public class SessionCounterListener implements HttpSessionListener {
 
  private static int totalActiveSessions;
  
  private Logger logger = Logger.getLogger(SessionCounterListener.class);
 
  public static int getTotalActiveSession(){
	return totalActiveSessions;
  }
 
  @Override
  public void sessionCreated(HttpSessionEvent sessionEvent) {
	totalActiveSessions++;
	logger.debug("sessionCreated - add one session into counter.Session=" + sessionEvent.getSession());
  }
 
  @Override
  public void sessionDestroyed(HttpSessionEvent sessionEvent) {
	totalActiveSessions--;
	logger.debug("sessionDestroyed - deduct one session from counter.Session=" + sessionEvent.getSession());
  }	
}
